import {generateUUID, isNullOrUndefined, mergeFromObject} from "./core";


//新的对话框
import {defaultSksTableColumnData} from "./sks-app-utils";

export function newSksDialogInfo(){
    return {
        //对话框ID
        uid:undefined,
        title: '',
        width: '500px',
        selectLabel: '选择',
        selectCallback: undefined,
        selectRowClick: true,
        showQueryForm: false,

        //不可编辑
        readonly: false,
        //编辑数据对话框使用
        //推荐返回数据格式
        //submitCallback:({submitData})=>{}
        submitCallback: undefined,
        showDialog: false,
    }
}

//新的 mainTable
export function newSksTable(){
    return  {
        //主键
        uniqueId: undefined,

        mainSksApp: undefined,
        //应用名
        sksAppName: undefined,
        //使用 tableColumnList 渲染
        tableColumnListEnable: false,
        //自动获取的列信息
        tableColumnList: undefined,

        //使用 queryParamsColumnList 渲染
        queryParamsColumnListEnable: false,
        //自动获取的搜索信息
        queryParamsColumnList: undefined,


        //表过滤标签页
        tabsFilterValue: undefined,
        //表过滤标签页选项
        tabsFilterOptionList: undefined,
        //变更标签页前要设置的默认值
        tabsSksParamsDefaultSetting: {},

        dataType: 1,

        queryParams:{
            sksParams:{},
            sksParamsLabel:{},
            start: 0,
            limit: 100,
            pageSize: 10,
            pageNum: 1,
        },
        list:[],
        total: 0,
        loading: true,

        //当前存在单选项,true 禁用
        single : true,
        //当前存在多选项,true 禁用
        multiple : true,
        //点击的行
        currentRow: {},
        //勾选的行ID集合
        ids:[],
        // 勾选的行
        selection: [],

        showTable: true,

        //是否显示属性名
        showTablePropName: false,

        showAllColumnButton: true,
        showAllColumn: false,

        showSearchButton: false,
        showSearch: true,

        //是否显示分页条
        showPagination: true,

        uuid: generateUUID(),
        //el-table 中的主键属性名,不设置拖动排序将不会刷新排序
        rowKey: 'vueVirtualUUID',
        //拖动排序
        dragSort: false,
        //拖动排序字段名
        dragSortPropName: 'sort',
        dragSortTableTmp: undefined,

        //true: 启用删除缓存,删除的行会以横线展示,false: 将会直接删除行
        deleteCacheHorizontalLine: true,

        //默认展开所有行
        defaultExpandAll: false,

        //表格高度
        tableHeight: undefined,
    }
}

export function newTableColumn(tc){
    return mergeFromObject({},defaultSksTableColumnData,tc,{
        vueVirtualUUID: generateUUID(),
    })
}

/**
 *
 * @param tcList
 * @return {*[]}
 */
export function newTableColumnList(tcList=[]){
    let tmp=[]
    if (isNullOrUndefined(tcList)) {
        return tmp
    }
    for (let tc of tcList) {
       tmp.push(newTableColumn(tc))
    }
    return tmp
}
